import numpy as np
from PIL import Image

from .model import generator_model
from .utils import load_image, deprocess_image, preprocess_image
from .config import model_path

def deblur(image):
    data = {
        'A': np.array([preprocess_image(image)])
    }
    x_test = data['A']
    g = generator_model()
    g.load_weights(model_path)
    generated_images = g.predict(x=x_test)
    generated = np.array([deprocess_image(img) for img in generated_images])
    x_test = deprocess_image(x_test)

    for i in range(generated_images.shape[0]):
        x = x_test[i, :, :, :]
        img = generated[i, :, :, :]
        # output = np.concatenate((x, img), axis=1)
        im = Image.fromarray(img.astype(np.uint8))
        return im
        # im.show()

# @click.command()
# @click.option('--image_path', help='Image to deblur')
# def deblur_command(image_path):
#     return deblur(image_path)


if __name__ == "__main__":
    deblur('F:\\image4.tif')
